
#include "find_all.h"
#include "substitute_all.h"
#include "tab2spaces.h"
#include "strip_all.h"


#include <iostream>
#include <string>


using namespace std;

int main(){


  cout << "\n\t\t example to test the find_all function";
  cout << "\n\tfind_all finds all occurences of a substring inside a string.\n\n";
  cout << "\n\treturn the position of the substring first character in a vector<size_t>";
  cout << "\n\t\t\t ---------------\n\n";

  string input = "Summer has come\nLoudly sing, cuckoo!\nGrows the seed and blossoms the meadow\nAnd the woods is back again\nSing, cuckoo!";

  cout << "\n\tinput string:\n\n";
  cout << input << endl << endl;

  cout << "\n\t looking for the substring: \"the\":\n";

  vector<size_t> v = find_all( input, "the");
  for (size_t i=0; i<v.size(); i++)
    cout << "\n\tposition: " << v[i];

  cout << "\n\n\t looking for the substring: \"\\n\":\n";

  v.clear();
  v = find_all( input, "\n");
  for (size_t i=0; i<v.size(); i++)
    cout << "\n\tposition: " << v[i];

  cout << endl << endl << endl << endl;


  cout << "\n\t\t example to test the substitute_all function";
  cout << "\n\t finds all occurences of a substring inside a string and make a substitution\n\n";
  cout << "\n\treturn the new string";
  cout << "\n\t\t\t ---------------\n\n";


  string in = "XX ebv XX ewv pwg XX ev XX ";
  string out = substitute_all( in, "X ", "pippo   " );


  cout << "\n\t substituting all \"X \" with \"pippo   \"";
  cout << "\n\t  in: \""  << in << "\"";
  cout << "\n\t out: \""  << out << "\"";



  cout << endl << endl << endl << endl;


  cout << "\n\t\t example to test the tab2spaces function";
  cout << "\n\t finds all occurences of a tab inside a string and substitutes with spaces\n\n";
  cout << "\n\t return the new string";
  cout << "\n\t\t\t ---------------\n\n";


  in.clear();
  in = "tab:\tand then spaces:   and then 2 tabs:\tx\t";
  cout << "\n\t input string : \"" << in << "\"";
  cout << "\n\t output string: \"" << tab2spaces( in ) << "\"";
  cout << "\n\t 5 spaces instead of 8: \"" << tab2spaces( in, 5 ) << "\"";


  cout << endl << endl << endl << endl;


  cout << "\n\t\t example to test the strip_all function";
  cout << "\n\t finds all occurences of a substring inside a string and split the original string\n\n";
  cout << "\n\t return a vector of strings";
  cout << "\n\t\t\t ---------------\n\n";

  in.clear();
  in = "XX ebv XX ewv pwg XX ev XX ";

  cout << "\n\t input:   \"" << in << "\"";
  cout << "\n\t position :" << "0123456789*123456789*123456789*123456\n";
  cout << "\n\t strip_all on \" XX \"; beware of the leading space!" << endl;
  vector<string> splitted = strip_all( in, " XX " );
  vector<size_t> posi = find_all( in, " XX " );

  for ( size_t i=0; i<splitted.size(); i++ )
    cout << "\n\t\telement " << i << ", value: \"" << splitted[i] << "\", position: " << posi[i];


  cout << "\n\t substitution check: \" XX\" --> \"---\": \"" << substitute_all( in, " XX ", "---" ) << "\"" << endl;

  cout << "\n\t same exercise, but now *do not want* empty results in the splitted vector:\n";
  splitted.clear();
  splitted = strip_all( in, " XX ", false );

  for ( size_t i=0; i<splitted.size(); i++ )
    cout << "\n\t\telement " << i << ", value: \"" << splitted[i] << "\", position: " << posi[i];

  splitted.clear();
  cout << "\n\t same exercise, but now *split using spaces*:\n";
  splitted = strip_all( in, " " );
  posi.clear();
  posi = find_all( in, " " );

  for ( size_t i=0; i<splitted.size(); i++ )
    cout << "\n\t\telement " << i << ", value: \"" << splitted[i] << "\", position: " << posi[i];



  cout << endl << endl;



  return 0;
}

